## setup ##

# clean environment
rm(list=ls())

# load packages
library(xlsx)
library(sandwich)
library(lmtest)
library(tidyverse)
library(xtable)


# load data
dat <- read.csv2("data_experiment_covariates_csv.csv",
                 encoding = 'UTF-8')


dat_tab_a2 <- dat %>% group_by(state, party) %>%
  summarise(mig_share = mean(migrant)*100) %>% 
  mutate(native_share = round(100 - mig_share, digits = 2)) %>% 
  select(-mig_share) %>% 
  pivot_wider(names_from = party, values_from = native_share )  # most recent version of tidyverse is required for this command

dat_tab_a2 <- xtable(dat_tab_a2) 
dat_tab_a2

# Output of Latex and HTML Version of table A2
   print.xtable(dat_tab_a2, type="html", file="tab_a2.html")
   print.xtable(dat_tab_a2, type="latex", file="tab_a2.tex")


